<cfparam name = "b_title" default="">
<cfparam name = "b_brief" default="">
<cfparam name = "b_author" default="">
<cfparam name = "b_content" default="">
<cfparam name = "errormsg" default="">
<cfparam name = "errorfields" default="">
<cfparam name = "b_postedon" default="#now()#">
<cfparam name = "b_hour" default="#timeformat(now(), 'h')#">
<cfparam name = "b_minute" default="#timeformat(now(), 'mm')#">
<cfparam name = "b_ampm" default="#timeformat(now(), 'tt')#">
<cfparam name = "b_id" default="0">
<cfparam name = "cid" default="0">
<cfset showform = 1>
<cfparam name = "formaction" default = "ADD">

<cfif isdefined('form.b_title')>
  <cfset showform = 0>
  <cfinvoke component="cfcs.common.validation" method="validate" fields="#form#" returnvariable="qValidation" />
  <cfif qValidation.recordcount GT 0>
    <cfset showform = 1>
    <cfsavecontent variable="errormsg">
    <cfoutput query = "qValidation">
      <cfset errorfields = listappend(errorfields, qValidation.fields)>
      #messages#<br>
    </cfoutput>
    </cfsavecontent>
    <cfelse>
    <cfinclude template="../act/insertpost.cfm">
  </cfif>
</cfif>
<cfif showform IS 1>
  <cfif formaction IS 'EDIT'>
    <cfinvoke component="cfcs.blog" method="getpost" b_id="#b_id#" returnvariable="qblog" />
    <cfset b_title = qblog.b_title>
    <cfset b_brief = qblog.b_brief>
    <cfset b_postedon = qblog.b_postedon>
    <cfset b_hour = timeformat(qblog.b_postedon, "hh")>
    <cfset b_minute = timeformat(qblog.b_postedon, "mm")>
    <cfset b_ampm = timeformat(qblog.b_postedon, "tt")>
    <cfset b_content = qblog.b_content>
    <cfset cid = qblog.categories>
    <cfset b_author = qblog.b_author>
  </cfif>
  <cfif len(trim(b_author)) IS 0 AND formaction IS 'ADD'>
    <cfinvoke component="cfcs.admin.admin" method="getuserinfo" userid="#session.id#" returnvariable="quser" />
    <!---get user logged in so we can fill in author--->
    <cfoutput query="quser">
      <cfset b_author = quser.fullname>
    </cfoutput>
  </cfif>
  <cfoutput>
    <script language="javascript">
function refreshcats() {
ColdFusion.navigate('#request.absoluteadminpath#components/blog/dialogs/categoryselect.cfm?cid=#cid#', 'categories');
}
</script>
    <cfif len(trim(errormsg)) GT 0>
      <div id="messages_error">#errormsg#</div>
    </cfif>
    <cfform action="index.cfm?c=blog&a=new&formaction=#formaction#&b_id=#b_id#" method="post" name="blogform" id="blogform">
    <table width="100%" border="0" cellspacing="0" cellpadding="6">
      <tr>
        <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="50%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="6">
                  <tr>
                    <td width="25%" valign="top">Author:</td>
                    <td><input name="b_author2" type="text" id="b_author" size="30" value="#b_author#" />
                      <br />
                      (Leave blank if you don't want to show an Author)</td>
                  </tr>
                  <tr>
                    <td valign="top">Title</td>
                    <td><cfinput name="b_title" type="text" id="b_title" value="#b_title#" size="55" maxlength="140" />
                      <br />
                      140 Characters Max</td>
                  </tr>
                  <tr>
                    <td valign="top">Date:</td>
                    <td><cfinput type="datefield" mask="mm/dd/yyyy" name="b_postedon" value="#dateformat(b_postedon, 'mm/dd/yyyy')#" id="b_postedon">
                      mm/dd/yyyy format </td>
                  </tr>
                  <tr>
                    <td valign="top">Time:</td>
                    <td><cfselect name="b_hour">
                      <cfloop from="1" to="12" index="hr">
                        <cfoutput>
                          <option value="#hr#" <cfif b_hour IS hr>selected="selected"</cfif>>#hr#</option>
                        </cfoutput>
                      </cfloop>
                      </cfselect>
                      <cfselect name="b_minute">
                      <cfloop from="0" to="59" index="mi">
                        <cfoutput>
                          <option value="#mi#" <cfif b_minute IS mi>selected="selected"</cfif>>#numberformat(mi, "00")#</option>
                        </cfoutput>
                      </cfloop>
                      </cfselect>
                      <cfselect name="b_ampm">
                      <option value="am" <cfif b_ampm IS 'am'>selected="selected"</cfif>>am</option>
                      <option value="pm" <cfif b_ampm IS 'pm'>selected="selected"</cfif>>pm</option>
                      </cfselect></td>
                  </tr>
                </table></td>
              <td width="50%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="6">
                  <tr>
                    <td width="35%" valign="top">Categories [<a href="##" onclick="editcategories();">Edit</a>]:</td>
                    <td><cfdiv id="categories">
                      <cfinclude template="../dialogs/categoryselect.cfm">
                      </cfdiv></td>
                  </tr>
                </table></td>
            </tr>
          </table></td>
      </tr>
      <tr>
        <td colspan="2" valign="top">Short Article (shown when browsing, usually the top part of the full article below)</td>
      </tr>
      <tr>
        <td colspan="2" valign="top"><textarea name="b_brief" id="b_brief" style="width: 100%; height: 175px;" class="tinymce">#b_brief#</textarea></td>
      </tr>
      <tr>
        <td colspan="2" valign="top">Full Article</td>
      </tr>
      <tr>
        <td colspan="2" valign="top"><textarea name="b_content" id="b_content" style="width: 100%; height: 400px;" class="tinymce">#b_content#</textarea></td>
      </tr>
      <tr>
        <td></td>
        <td><div align="left">
            <cfinput type = "hidden" value="b_title|Title is required;b_brief|You must enter a brief summary of the article;b_content|You must enter some sort of content in order to post a blog entry." name="validate_require">
            <input type="submit" name="abutton" id="abutton" value="Save and Post Now" onclick="tinyMCE.triggerSave();" />
          </div></td>
      </tr>
      <tr>
        <td colspan="2" align="left"><cfdiv id="saveresults" style="text-align: left; width: 250px;"></cfdiv>
        </td>
      </tr>
    </table>
    </cfform>
  </cfoutput>
</cfif>
<cfoutput>
  <div id="dialog" style="display: none; font-size: 10pt;">
    <div>
      <iframe style="border: 0px;" src="#request.absoluteadminpath#components/blog/dialogs/editcategories.cfm" width="100%" height="430"></iframe>
    </div>
  </div>
</cfoutput>